var app = getApp(), fetchApi = require("../../../utils/httpPost.js"), 
i = require("../../../utils/arrayUtil.js")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    serviceList:[],
    goodsList:[],
    pageSize:10,
    pageIndex:1,
    longitude:0,
    latitude:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.modalcnt()
  },
  onShow:function(){
  },
  modalcnt:function  ()  {
    var  that  =  this
    that.data.pageIndex = 1
    //获取经纬度  
    wx.getLocation({
      type:  'gcj02',
      success:  function  (res)  {
        console.log('modalcnt', res)
        var latitude = res.latitude
        var longitude = res.longitude
        that.data.latitude = latitude//纬度
        that.data.longitude = longitude//经度
        that.setData({
          latitude : latitude,
          longitude : longitude
        })
        that.onHttpInit()
      },fail:function(res){
        that.data.wd = 0
        that.data.longitude = 0
        that.onHttpInit()
      }
    })
  },
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost("/product/type/list", {
      parent_id: 2,
      pageSize:that.data.pageSize,
      pageIndex: that.data.pageIndex,
      longitude: that.data.longitude,
      latitude: that.data.latitude,
    }, function (res) {
      console.log("获取商家服务类型返回数据:", res)
      that.setData({
        serviceList: res.data.data.types,
        goodsList: res.data.data.products,
      });
    }, function (a) {
      console.log("获取商家服务类型返回数据 err:", a);
    });
  },
  onClickServiceType: function (res) {
    var type_id = res.target.dataset.id
    var that = this
    fetchApi.httpPost("/product/list", {
      type_id:type_id,
      pageSize:that.data.pageSize,
      pageIndex: that.data.pageIndex,
      longitude: that.data.longitude,
      latitude: that.data.latitude,
    }, function (a) {
      console.log("获取商家服务类型返回数据:", a)
      that.setData({
        goodsList: a.data.data,
      });
    }, function (a) {
      console.log("获取商家服务类型返回数据 err:", a);
    });
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})